package com.zdc.learn.netty.codec;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * 自定义编码器
 */
public class MessageEncoder extends MessageToByteEncoder<MessageStyle> {
    @Override
    protected void encode(ChannelHandlerContext ctx, MessageStyle msg, ByteBuf out) throws Exception {
        System.out.println("MessageEncoder 被调用............");
        out.writeInt(msg.getLen());
        out.writeBytes(msg.getContent());
    }
}
